﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class EditMenuTop : System.Web.UI.UserControl
    {
        public string catename;
        public string image;
        public string description;
        public string showcateleft;
        public int intactivetop;
        public int intactiveleft;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Request.QueryString["catid"] != null)
                {
                    int cateid = Convert.ToInt32(Request.QueryString["catid"]);
                    DataTable dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereID("tbl_Category", "Category_ID1", cateid.ToString());
                    catename = dt.Rows[0]["Category_Name"].ToString();
                    description = dt.Rows[0]["Category_Description"].ToString();

                    txtCateName.Text = catename;
                    CKEditorMota.Text = description;
                }
            }
            catch (Exception)
            {
                Response.Redirect("/Admin/error.htm");
            }
        }

        protected void btnUpdateCate_Click(object sender, EventArgs e)
        {
            int cateid = Convert.ToInt32(Request.QueryString["catid"]);
            string catename = txtCateName.Text;
            string description = CKEditorMota.Text;
            if (catename != "")
            {

                DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[2];
                cl[0] = new DAL.DHelpers.Column("Category_Name", catename, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                cl[1] = new DAL.DHelpers.Column("Category_Description", description, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);

                string[] colWhere = new string[1];
                colWhere[0] = "Category_ID1";

                object[] colValue = new object[1];
                colValue[0] = cateid;

                DAL.DCollector.DBCollector.Instance.Update("tbl_Category", cl, colWhere, colValue);
                Response.Redirect("/Admin/Index.aspx?panel=2&sub=1");
            }
            else
            {
                Response.Write("<script>alert('Vui lòng nhập tên menu...')</script>");
            }
        }
    }
}